import java.util.*;

public class Clockface {

	public int[] Clockarray; 
	public int clocksize;
	public Queue<Integer> clockpath;
	public Queue<Integer> successpath;
	
	public Clockface(int size){
		clocksize = size;
		Clockarray = new int[clocksize];
	};
	
	int set( int index, int number){
		Clockarray[index-1] = number;
		return index;
	};
	
	void getsolution(){
		for (int i = 1; successpath.isEmpty(); i++ ){
			solve (Clockarray, i, clockpath);
		}
	}
	
	void solve(int[] array, int start, Queue<Integer> path){
		while (successpath.isEmpty()){
			int start1 = ((start-1 - array[start-1])%clocksize)+1;
			int start2 = ((start-1 + array[start-1])%clocksize)+1;
			set(start, 0);
			Queue.add(start);
			if (start1 != 0){
				solve( array, start1, path);
			}
			if (start2 != 0){
				solve( array, start1, path);
			}
			if (path.size()==clocksize){
				successpath.addAll(path);
			}
		}
	}
	
}
